//   Copyright 2009 Pyxis Technologies
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//
using Pyxis.FluentSelenium.Locator;
using Selenium;

namespace Pyxis.FluentSelenium.Tester
{
    public class TableColumnTester
    {
        private readonly ISelenium selenium;
        private readonly string parentLocator;
        private readonly int columnIndex;

        public TableColumnTester(ISelenium selenium, string parentLocator, int columnIndex)
        {
            this.selenium = selenium;
            this.parentLocator = parentLocator;
            this.columnIndex = columnIndex;
        }

        public void ShouldSee(params string[] expectedValues)
        {
            for (var rowNumber = 1; rowNumber <= expectedValues.Length; rowNumber++)
            {
                var cellLocator = CreateCellLocator(rowNumber);
                var expectedValue = expectedValues[rowNumber - 1];
                var acctualText = selenium.GetText(cellLocator.ToString());
                
                if (expectedValue != acctualText)
                    ConditionError.ContentNotMatch(expectedValue, acctualText, cellLocator, rowNumber);
                    //Assert.AreEqual(expectedValue, acctualText);
            }
        }

        private ElementLocator CreateCellLocator(int rowNumber)
        {
            var cellLocatorFormat = "{0}//tr[{1}]/td[{2}]";
            var locator = string.Format(cellLocatorFormat, parentLocator, rowNumber + 1, columnIndex);
            return ElementLocator.WithXpath(locator);
        }
    }
}
